<?php
class authorization extends module {
	public $title = "Authorization form";
	public $frame = "main";
	
	public function run() {
		$formTitle = sprintf(_("Sign in to %s"), SITE_NAME);
		$form = new formConstructor($this, "authorization", "", $formTitle);
		$form->addField("goto", "", new formHidden(isset($_GET['goto'])?$_GET['goto']:""));
		$form->addField("login", _("Login"), new formString(), _('it should be your email'));
		$form->addField("password", _("Password"), new formPassword());
		$form->addField(null, _("Sign in"), new formSubmit());
		
		if ($form->submit()) {
			if ($this->user->authorization($form->getValue("login"), $form->getValue("password"))) {
				if ($form->getValue("goto") ==  "") {
					$this->engine->jump(USER_HOME_URL);
				} else {
					$this->engine->jump($form->getValue("goto"));
				}
			} else {
				new pageAlert($this, _("Invalid login or password. Please try again."));
			}
		}

		$form->write();
	}

	public function logout() {
		$this->user->logout();
	}
	
	public function quickAuthorization () {
		if ($this->user->role == ROLE_GUEST) {
			$this->run();
		} else {
			$this->xml->authorized = 1;
		}
	}
}
?>